package arity.calculator.plus;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class CalculatorActivity extends Activity
{
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.calculator_activity_new);
		
		((TextView) findViewById(R.id.equation_result)).setText("1234567890.123");
		((EditText) findViewById(R.id.equation_input)).setText("1+2+3");
	}
	
	// TODO: remove XML onClick attribute from kb_calculator.xml styling, as this
	// couples the Activity to the Fragment. Within KeyboardCalculatorFragment.java
	// manually assign the onClickListener for each button to be a callback with
	// the Activity implementing the callback interface.
	public void onSoftKey(View view)
	{
		EditText equationInput = (EditText) findViewById(R.id.equation_input);
		
		switch (view.getId())
		{
		case R.id.kb_control_backspace:
			{
				equationInput.dispatchKeyEvent(new KeyEvent(0, KeyEvent.KEYCODE_DEL));
			}
			break;
			
		default:
			{
				equationInput.getText().insert(equationInput.getSelectionStart(), ((TextView) view).getText());
			}
			break;
		}
	}
}
